package araxy.blog.utils;

import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;

import static java.nio.file.StandardOpenOption.*;

public class NIOUtil {
    public static void copyFileCover(Path src, Path dest) throws IOException {
        if (!Files.exists(src)) {
            throw new IOException();
        }
        if (Files.exists(dest)) {
                Files.delete(dest);
        }
        FileChannel in = FileChannel.open(src,READ);
        FileChannel out = FileChannel.open(dest,WRITE,CREATE_NEW);
        in.transferTo(0,in.size(),out);
        in.close();
        out.close();
    }

}
